#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
const int MSGBUFF = 10240;
int main()
{
	int sock;
	sock = socket(AF_INET, SOCK_DGRAM, 0);
	if(-1 == sock)
    {
      printf("socket() error\n");
      return -1;
    }
    struct sockaddr_in svraddrSend;
    svraddrSend.sin_family = AF_INET;
    svraddrSend.sin_addr.s_addr = inet_addr("10.3.0.20");
    svraddrSend.sin_port = htons(5111);
    
    if (bind(sock, (struct sockaddr*)&svraddrSend, sizeof(struct sockaddr_in)) )
    {
		printf("bind() error\n");
		return -1;
	}
	
	struct sockaddr_in destaddr;
    destaddr.sin_family = AF_INET;
    destaddr.sin_addr.s_addr = inet_addr("233.31.1.1");
    destaddr.sin_port = htons(5100);
    
    char buffer[10240] = "aaaaaaaaaaaaaaaa";
		
    while(1)
    {
		
		int sendlen = rand()% MSGBUFF;
		
		if ( sendto(sock,buffer,sendlen,0,(struct sockaddr *)&destaddr,sizeof(struct sockaddr_in)) < 0)
		{
			printf("sendto() error\n");
			exit(0);
		}
                 sleep(1);

		printf("sendlen = %d\n",sendlen);
		
	}
	close(sock);
}
